package com.example.wechattakeaway.controller;

import com.example.wechattakeaway.accessctro.RolePermission;
import com.example.wechattakeaway.form.merdishform.InsertMerDishForm;
import com.example.wechattakeaway.form.merdishform.UpdateMerDishForm;
import com.example.wechattakeaway.service.MerDishService;
import com.example.wechattakeaway.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/MerDishController")
@Api(tags = "菜品信息管理模块")
public class MerDishController {
    @Autowired
    MerDishService merDishService;


    @ApiOperation(value = "添加菜品信息",notes = "商家web端")
    @PostMapping("/insertMerDish")
    public ResultVO insertMerDish(InsertMerDishForm insertMerDishForm){

        return merDishService.insertMerDish(insertMerDishForm);
    }

    @ApiOperation(value = "编辑菜品信息",notes = "商家web端")
    @PostMapping("/updateMerDish")
    public ResultVO updateMerDish(UpdateMerDishForm updateMerDishForm){

        return merDishService.updateMerDish(updateMerDishForm);
    }

    @ApiOperation(value = "根据菜品id查询对应菜品",notes = "小程序端以及商家web端")
    @ApiImplicitParam(name="dishId",value="菜单id",example = "1",dataType = "Integer",paramType = "query")
    @GetMapping("/selectDishById")
    public ResultVO selectDishById(@RequestParam("dishId") Integer dishId){
        log.info(dishId.toString());
        return merDishService.selectDishById(dishId);
    }

    @ApiOperation(value = "根据商家id查询对应所有菜品列表",notes = "小程序端")
    @ApiImplicitParam(name="merchantId",value="菜单id",example = "1",dataType = "Integer",paramType = "query")
    @GetMapping("/selectDishByMerchantId")
    public ResultVO selectDishByMerchantId(@RequestParam("merchantId") Integer merchantId){
        log.info("当前是商家管理员试着查询菜品");
        return merDishService.selectDishByMerchantId(merchantId);
    }

    @ApiOperation(value = "根据菜单id查询对应菜品列表(分页)",notes = "商家Web端")
    @ApiImplicitParam(name="menuId",value="菜单id",example = "1",dataType = "Integer",paramType = "query")
    @GetMapping("/selectDishByMenuId")
    public ResultVO selectDishByMenuId(@RequestParam("pageNum") Integer pageNum,@RequestParam("menuId") Integer menuId){

        return merDishService.selectDishByMenuId(pageNum,menuId);
    }

    @ApiOperation(value = "根据菜单id查询对应菜品列表",notes = "小程序端")
    @ApiImplicitParam(name="menuId",value="菜单id",example = "1",dataType = "Integer",paramType = "query")
    @GetMapping("/selectByMenuId")
    public ResultVO selectByMenuId(@RequestParam("menuId") Integer menuId){

        return merDishService.selectByMenuId(menuId);
    }

    @ApiOperation(value = "根据菜品id更新菜品图片",notes = "web端")
    @PostMapping("/UpdateDishPhotoById")
    public ResultVO UpdateDishPhotoById(@RequestParam("file") MultipartFile file,Integer merchantId){
        return merDishService.UpdateDishPhotoById(file, merchantId);
    }

    @ApiOperation(value = "根据菜品id删除菜品",notes = "商家web端")
    @PostMapping("/deleteMerDish")
    public ResultVO deleteMerDish(Integer dishId){

        return merDishService.deleteMerDish(dishId);
    }
}
